<cfcomponent output="false">


	<cffunction name="GetAllReports" output="true" access="remote" returntype="Report[]">
		<cfset var qRead="">
		<cfset var obj="">
		<cfset var reports=arrayNew(1)>

		<cfquery username="#request.username#" password="#request.password#" name="qRead" datasource="nwharvest">
		SELECT FOODDRIVES.ID as ID,
					ORGANIZATIONS.ORG_NAME as ORGANIZATION,
					USERS.FNAME + ' ' + USERS.LNAME	as ADMINISTRATOR,
					USERS.EMAIL,
					FOODDRIVES.START_DATE,
					FOODDRIVES.END_DATE,
					FOODDRIVES.GOAL,
					SUM( DONATIONS.AMOUNT ) as CURRENT_DONATION
		FROM ( ( FOODDRIVES INNER JOIN ORGANIZATIONS ON FOODDRIVES.ORG_ID = ORGANIZATIONS.ID ) 
						INNER JOIN USERS ON ORGANIZATIONS.ADMIN_ID = USERS.ID ) LEFT OUTER JOIN DONATIONS ON FOODDRIVES.ID = DONATIONS.FOODDRIVE_ID
		GROUP BY FOODDRIVES.ID, ORGANIZATIONS.ORG_NAME, USERS.FNAME + ' ' + USERS.LNAME, USERS.EMAIL, FOODDRIVES.START_DATE,FOODDRIVES.END_DATE, FOODDRIVES.GOAL
		ORDER BY FOODDRIVES.ID
		</cfquery>

		<cfoutput query="qRead">
		<cfscript>
			obj = createObject("component", "Report");

			obj.ID = qRead.ID;
			obj.ORGANIZATION = qRead.ORGANIZATION;
			obj.ADMINISTRATOR = qRead.ADMINISTRATOR;
			obj.EMAIL = qRead.EMAIL;
			obj.START_DATE = qRead.START_DATE;
			obj.END_DATE = qRead.END_DATE;
			obj.CURRENT_DONATION = qRead.CURRENT_DONATION;
			obj.GOAL = qRead.GOAL;

			ArrayAppend(reports, obj);
		</cfscript>
		</cfoutput>

	  <cfdump var="#reports#"/>

		<cfreturn reports>
	</cffunction>

</cfcomponent>